package com.hzw.saas.api.storage.enums;

import java.util.Objects;

/**
 * 资源权限
 *
 * @author zzl
 * @since 02/26/2021
 */
public enum ResourceAuthEnum {

    READ(1, "读取"),
    WRITE(2, "写入"),
    DELETE(3, "删除"),
    OWN(9, "完全控制权限"),
    ;

    private final Integer code;
    private final String text;

    ResourceAuthEnum(Integer code, String text) {
        this.code = code;
        this.text = text;
    }

    public Integer getCode() {
        return code;
    }

    public String getText() {
        return text;
    }

    public static String getText(Integer code) {
        for (ResourceAuthEnum value : ResourceAuthEnum.values()) {
            if (Objects.equals(value.code, code)) {
                return value.text;
            }
        }
        return "";
    }

    public static ResourceAuthEnum instance(Integer code) {
        for (ResourceAuthEnum value : ResourceAuthEnum.values()) {
            if (Objects.equals(value.code, code)) {
                return value;
            }
        }
        return ResourceAuthEnum.READ;
    }


}
